// components/like/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    like: {
      type: Boolean
    },
    count: {
      type: Number
    },
    readOnly: {
      type: Boolean
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    yesSrc: 'images/like.png',
    noSrc: 'images/like@dis.png'
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onLike: function (evt) {
      let { readOnly, like, count } = this.properties
      if (readOnly) { return; }
      like ? count-- : count++
      like = !like
      this.setData({count,like})
      let behavior = like ? 'like' : 'cancel'
      this.triggerEvent('like', { behavior },{})
    }
  }
})
